package com.dgshanger.sanhxiaofeisc.mvp.presenter;

import com.dgshanger.sanhxiaofeisc.entity.VipEntity;
import com.dgshanger.sanhxiaofeisc.mvp.contract.RechargeContract;
import com.dgshanger.sanhxiaofeisc.mvp.model.RechargeModel;
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter;
import com.xx.baseutilslibrary.network.rx.RxHttpObserver;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * RechargePresenter
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/4/30 17:48.
 */

public class RechargePresenter extends BaseRxMvpPresenter<RechargeContract.Model, RechargeContract.View> implements RechargeContract.Presenter {
    @NotNull
    @Override
    protected RechargeContract.Model createModel() {
        return new RechargeModel();
    }

    @Override
    public void loadRechargeInfo() {
        getModel().loadRechargeInfo(new RxHttpObserver<VipEntity>() {
            @Override
            public void onCompleted(@Nullable String msg, @Nullable VipEntity entity) {
                if (getView() == null) {
                    return;
                }
                getView().setData(entity);
            }

            @Override
            public void onError(@Nullable String error) {
                if (getView() == null) {
                    return;
                }
                getView().showError(new Throwable(error), false);
            }

            @Override
            public void onLoadingStart() {
                setLoading(true);
                getView().setRefresh(false);
            }

            @Override
            public void onLoadingFinish() {
                setLoading(false);
                getView().setRefresh(false);
            }
        });
    }
}
